$(document).ready(function (){
    var userstring = sessionStorage.getItem('user');
    var user = JSON.parse(userstring);
    var nickname=user.nickname;
    var uid=user.id;
       $('#nickname').text(nickname);
        $.get("view/show",{"uid":uid},function (rs){
            var items = rs.result;
            var $ul = $("[name='body']");
            $ul.empty(); // 清空现有的 <li>
            for (var i = 0; i < items.length; i++) {
                var item = items[i];
                $("<li>\n" +
                    "    <a href='#' name='" + item.id + "' title='图片'><img src='" + item.image + "'></a>\n" +
                    "    <h4><a href='#'>" + item.fname + "</a></h4>\n" +
                    "    <div class='prize'>￥" + item.price + "</div>\n" +
                    "</li>").appendTo("[name='body']");
            }
        });

    //点击图片跳转到详情
    $(document).on("click", "a[title='图片']", function () {
        var id = $(this).attr("name");
        $.get("view/add&del",{"uid":uid,"fid":id},function () {});
        window.location.href = "http://127.0.0.1:8881/detail.html?id=" + id;

    });

    $(document).on("click", ".goods_type_list a", function(event) {
        // event.preventDefault();
        // event.stopPropagation();
        var liId = $(this).closest('li').attr('id'); // 获取父 li 元素的 id
    });

    //alert(uid);
    $.get("pc/address/findbasic", {"id": uid}, function (basics) {
        $("[id='basicinfo']").empty();
        for (var i = 0; i < 1; i++) {
            $(" <li><span>用户名：</span>" +basics[i].sname+"</li>\n" +
                "   <li><span>联系方式：</span>"+basics[i].phone+"</li>\n" +
                " <li><span>联系地址：</span>"+basics[i].detailedaddress+"</li>").appendTo("[id='basicinfo']")
        }
    });
});
